package hu.blok1.veilingsite.client.gui;

import hu.blok1.veilingsite.client.Veilingsite;
import hu.blok1.veilingsite.shared.User;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

public class headerGUI {
	private HorizontalPanel hp, hp1, hp2, hp3;
	private Veilingsite vs;
	private User user;
	private VerticalPanel vp = new VerticalPanel();
	public headerGUI(HorizontalPanel a, Veilingsite v){
		vs = v;
		init(a);
	}
	
	public void init(HorizontalPanel a){
		user = vs.getUser();
		hp = a;
		hp.setHeight("100%");
		hp.clear();
		vp.clear();
		vp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		
		hp1 = new HorizontalPanel();
		hp1.setHeight(100 + "%");
		hp1.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		
		hp2 = new HorizontalPanel();
		hp2.setSpacing(15);
		
		hp3 = new HorizontalPanel();
		hp3.setHeight(100 + "%");
		hp3.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		hp3.setSpacing(15);
		
		Hyperlink home = new Hyperlink("Home", "home");
        Hyperlink login = new Hyperlink("Log-in", "login");
        Hyperlink createAccount = new Hyperlink("Account aanmaken", "accountaanmaken");
        Hyperlink logoff = new Hyperlink("Uitloggen", "logout");
        Hyperlink personalPage = new Hyperlink(user.getName() + " " + user.getLastName(), "personalPage");
        Hyperlink adminPage = new Hyperlink("Admin Panel", "adminIndex");
        Hyperlink addProduct = new Hyperlink("Product aanbieden", "userCreateProduct");
//        Hyperlink showProducts = new Hyperlink("Productoverzicht", "userCreateProductList");
//        Hyperlink showProductSpecifications = new Hyperlink("Product bekijken", "productSpecifications");
        
        vp.add(new Image("images/logo.png"));
		vp.setHeight(100 + "%");
		
        
        hp1.add(vp);
        hp1.add(hp3);
        
        hp3.add(home);
       
        if(!user.isLoggedIn()){
	        hp3.add(login);
	        hp3.add(createAccount);
        }else{
        	hp3.add(personalPage);
        	hp3.add(addProduct);
//        	hp3.add(showProducts);
//        	hp3.add(showProductSpecifications);
        	if(user.getUserType().equals("Admin")){
        		hp3.add(adminPage);
        	}
        	hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        	hp2.add(logoff);
        	
        }
        
        hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        hp.add(hp1);
        hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        hp.add(hp2);
	}
	
	public void reload(){
		init(hp);
	}
}
